package com.longtengyuyun.longadder;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.LongAdder;

/**
 * @author ZhaoYunLong
 * @date 2022/3/28
 * @description
 */
public class LongAdderTest {

    public static void main(String[] args) {
        Thread[] threads = new Thread[100];
        LongAdder longAdder = new LongAdder();
        for (int i = 0; i< threads.length; i++) {
            threads[i] = new Thread(()->{
                longAdder.increment();
            });
        }
        for (Thread thread : threads) {
            thread.start();
        }
        for (Thread thread : threads) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(longAdder.sum());
    }


}
